//
//  EpointSinglePickerViewController.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-3-6.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "EpointSinglePickerViewController.h"

@interface EpointSinglePickerViewController ()
{
    UITableView *tv;
    NSArray *strArr;
}
@end

@implementation EpointSinglePickerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    strArr = [self.passParam objectForKey:@"strArr"];
    tv = [[UITableView alloc]initWithFrame:[self getFullContentFrame] style:UITableViewStyleGrouped];
    tv.dataSource = self;
    tv.delegate = self;
    tv.backgroundView = nil;
    tv.backgroundColor = [UIColor clearColor];
    [self.view setBackgroundColor:COLOR(239, 239, 243)];
    [self.view addSubview:tv];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return strArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"simplecell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]init];
    }
    cell.textLabel.text = [strArr objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController popViewControllerAnimated:YES];
    self.singleSelectHandler(indexPath.row);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+(void)InvokeSinglePickerViewController:(UIViewController *)vc title:(NSString *) vctitle strArr:(NSArray *)strArr handler:(SingleSelectHandler)handler
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [params setObject:vctitle forKey:@"title"];
    [params setObject:strArr forKey:@"strArr"];
    EpointSinglePickerViewController *espv = [[EpointSinglePickerViewController alloc]init];
    espv.singleSelectHandler = handler;
    espv.passParam = params;
    [vc.navigationController pushViewController:espv animated:YES];
}

@end
